﻿using System;
using System.Collections.Generic;
using Color = System.Drawing.Color;
using SwinGame;
using System.Diagnostics;

namespace Jumpman.src
{
    public class Mario : GameElement
    {

        public Mario()
        {
            ElementSprite = Sprites.CreateSprite(Resources.LoadBitmap("mario.png"), 7, 3, 90, 85);
            ElementSprite.X = 200f;
            ElementSprite.Y = 0f; //original value 440
            IsStatic = false;

        }
        private IAction moveMarioLeft = new MoveAction("left");
        private IAction moveMarioRight = new MoveAction("right");
        public override void Draw()
        {
            ElementSprite.Draw();
            
        }

        public override void Update(GameController gc)
        {
            ElementSprite.Update();
            Camera.CenterCameraOn(gc.Player.ElementSprite, 200, -150);
            
            //Debug.WriteLine(IsFalling);

            if (Input.KeyDown(KeyCode.vk_RIGHT))
            {
                moveMarioRight.DoAction(gc);
            }
            

            if (Input.KeyDown(KeyCode.vk_LEFT))
            {
                moveMarioLeft.DoAction(gc);
            }
            

            if (Input.KeyTyped(KeyCode.vk_UP) && !IsFalling)
            {
                ElementSprite.Velocity.Y=-10;
            }

            

            if ((!Input.KeyDown(KeyCode.vk_RIGHT) && !Input.KeyDown(KeyCode.vk_LEFT)) ||(Input.KeyDown(KeyCode.vk_RIGHT) && Input.KeyDown(KeyCode.vk_LEFT)))
            {
              ElementSprite.Velocity.X = 0;
            }
            

        }

    }
}
